﻿using System.IO;
using MongoDB.Driver;
using MongoDB.Driver.GridFS;

namespace ZilLion.Service.Core.MongoDbManager.GridFs
{
    /// <summary>
    ///     Mongo文件存储Repository
    /// </summary>
    public interface IGridFsRepository : IMongoDbRepository
    {
        /// <summary>
        ///     RootName
        /// </summary>
        string RootName { get; set; }

        /// <summary>
        ///     GridFS
        /// </summary>
        MongoGridFS MongoGridFs { get; set; }

        /// <summary>
        ///     Server
        /// </summary>
        MongoServer MongoServer { get; set; }

        /// <summary>
        ///     <summary>
        ///         上传文件
        ///     </summary>
        ///     <param name="filePath"></param>
        ///     <returns></returns>
        MongoGridFSFileInfo UploadFile(string filePath);

        /// <summary>
        ///     上传文件
        /// </summary>
        /// <param name="fileStream"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        MongoGridFSFileInfo UploadFile(Stream fileStream, string fileName);

        /// <summary>
        ///     上传文件
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        MongoGridFSFileInfo UploadFile(byte[] bytes, string fileName);
        /// <summary>
        ///     删除文件
        /// </summary>
        /// <param name="key"></param>
        void DeleteFileById(string key);

        /// <summary>
        ///     删除文件
        /// </summary>
        /// <param name="fileName"></param>
        void DeleteFileByFileName(string fileName);


        #region 获取文件

        /// <summary>
        ///     GetFileAsBytesByKey
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        byte[] GetFileAsBytesByKey(string key);

        /// <summary>
        ///     GetFileAsStreamByKey
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        Stream GetFileAsStreamByKey(string key);

        /// <summary>
        ///     GetFileAsBytesByFileName
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        byte[] GetFileAsBytesByFileName(string fileName);

        /// <summary>
        ///     GetFileAsStreamByFileName
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        Stream GetFileAsStreamByFileName(string fileName);

        /// <summary>
        ///     TryDownloadFileByKey
        /// </summary>
        /// <param name="id"></param>
        /// <param name="targetPath"></param>
        /// <returns></returns>
        bool TryDownloadFileByKey(string id, string targetPath);

        /// <summary>
        ///     TryDownloadFileByFileName
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="targetPath"></param>
        /// <returns></returns>
        bool TryDownloadFileByFileName(string fileName, string targetPath);

        /// <summary>
        ///     GetFileAsStringByFileName
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        string GetFileAsStringByFileName(string filename);

        /// <summary>
        ///     GetFileAsStringByKey
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        string GetFileAsStringByKey(string key);

        #endregion
    }
}